<?php


namespace App\Extensions\Exporters;

use Carbon\Carbon;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;

class BookApplyExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '软件著作权申请列表.xlsx';
    protected $role = 0;

    protected $columns = [
        'uuid'          => '系统编号',
        'name'          => '名称',
        'inventor'      => '开发人',
        'applicant'     => '著作权人',
        'department_id' => '所属科室',
        'mobile'        => '联系电话',
        'register_no'   => '登记号',
        'complete_date' => '完成时间',
        'cert_date'     => '下证时间',
        'review_status' => '是否已审批',
        'status'        => '是否已授权',
        'user_id'       => '创建人',
        'created_at'    => '创建时间'
    ];

    public function map($row): array
    {
        return [
            $row->uuid,
            $row->name,
            $row->inventor,
            $row->applicant,
            $row->department->name ?? '',
            $row->mobile . "\t",
            $row->register_no,
            $row->complete_date,
            $row->cert_date . "\t",
            $row->review_status ? '是' : '否',
            $row->status ? '是' : '否',
            $row->user->name ?? '',
            Carbon::parse($row->created_at)->toDateString(),
        ];
    }

}
